package command;

abstract class ACommand{
    // 什么是命令不如粘贴复制等等。Command就是封装各种各样的指令的。
    abstract void exec();
    abstract void undo();
}

class Content{
    public String str = "test";
}

// 定义命令
class InsertContentCommand extends ACommand{
    private Content content;
    public InsertContentCommand(Content content){
        this.content = content;
    }
    public void exec(){
        content.str = content.str+"admin";
    }
    public void undo(){
        content.str = content.str.replaceAll("admin","");
    }
}

public class Command {
    public static void main(String[] args) {
        System.out.println("command");

        Content content = new Content();

        // InsertContentCommand
        InsertContentCommand insertContentCommand = new InsertContentCommand(content);
        insertContentCommand.exec();
        System.out.println(content.str);
        insertContentCommand.undo();
        System.out.println(content.str);
    }
}
